apiready = function() {
    seajs.use(['../../V', "../../api", "../../jquery", "../../app", "../../service", "../../dialog"], function(V, $api, $, app, service, dialog) {
        var vm = {
            el: '.container',
            data: {
                sendList: '',
                order_id: ''
            },
            mounted: function() {
                //--解决ios输入法挡住输入框的问题
                $(document).on("focus", "#aui-input", function() {
                    console.log($('body').scrollTop());
                    var top = $('body').scrollTop();
                    setTimeout(function() {
                        console.log(document.body.offsetHeight);
                        window.scrollTo(0, top + 100);
                    }, 50);
                });
            },
            methods: {
                getExpressList: function(callback) {
                    var shopId = api.pageParam.shopId; // 商店id
                    var unionid = $api.getStorage("shop_unionid"); // 用户id
                    var that = this;

                    app.ajax(service['getExpressList'], {
                            data: {
                                values: {
                                    shop_code: shopId,
                                    unionid: unionid,
                                }
                            }
                        },
                        function(res) {
                            if (res.code) {
                                api.toast({
                                    msg: res.message,
                                    duration: 2000,
                                    location: 'middle'
                                });
                            } else {
                                callback(res)
                                console.log("获取快递列表成功!");
                            }
                        });
                },
                //--手动添加其他快递
                shopSendBtn: function() {
                    var shopId = api.pageParam.shopId; // 商店id
                    var unionid = $api.getStorage("shop_unionid"); // 商家id
                    var that = this;

                    dialog.prompt({
                        title: "请填写快递名称",
                        text: "请填写快递名称",
                        buttons: ['取消', '确定']
                    }, function(ret) {
                        if (ret.buttonIndex == 2 && ret.text != "") {
                            express_name = $api.trim(ret.text);

                            if (express_name != '' && express_name != null) {
                                //--判断是否存在特殊字符
                                if (app.hasSpecialChar(express_name, '请正确填写快递公司名称')) {
                                    return false
                                };

                                app.ajax(service['setExpress'], {
                                        data: {
                                            values: {
                                                shop_code: shopId,
                                                unionid: unionid,
                                                express_name: express_name,
                                                express_code: ''
                                            }
                                        }
                                    },
                                    function(res) {
                                        if (res.code) {
                                            api.toast({
                                                msg: res.message,
                                                duration: 2000,
                                                location: 'middle'
                                            });
                                        } else {
                                            console.log("添加快递列表成功!");
                                            api.toast({
                                                msg: '添加快递列表成功!',
                                                duration: 2000,
                                                location: 'middle'
                                            });
                                            that.getExpressList(function(res) {
                                                that.sendList = res.data;
                                                console.log(JSON.stringify(that.sendList))
                                            })
                                        }
                                    });
                            } else {
                                api.toast({
                                    msg: '快递公司名称不能为空',
                                    duration: 2000,
                                    location: 'middle'
                                });

                                return
                            }

                        }
                    })
                },
                //--填写快递单号
                shopSendNumber: function(express_id, express_name, express_logo) {
                    var that = this;

                    dialog.prompt({
                        title: "请填写快递单号",
                        text: "请填写" + express_name + "的快递单号",
                        buttons: ['取消', '确定']
                    }, function(ret) {
                        var express_sn = ''; //分类名称
                        if (ret.buttonIndex == 2 && ret.text != "") {
                            express_sn = $api.trim(ret.text);

                            //--判断是否存在特殊字符
                            if (app.hasSpecialChar(express_sn, '请正确填写快递单号')) {
                                return false
                            };
                            //--判断是否仅为英文和数字
                            if (app.hasSpecialChar(express_sn, '请正确填写快递单号', 'LetterAndNumber')) {
                                return false
                            };

                            // app.openWin('shopSendDetail', {
                            // 	shopId: api.pageParam.shopId,
                            // 	order_id: that.order_id,
                            // 	express_id: express_id,
                            // 	express_name: express_name,
                            // 	express_sn: express_sn
                            // });

                            api.openFrame({
                                name: 'shopSend',
                                url: './shop_send_detail.html',
                                rect: {
                                    x: 0,
                                    y: 0,
                                    w: 'auto',
                                    h: 'auto'
                                },
                                pageParam: {
                                    shopId: api.pageParam.shopId,
                                    order_id: that.order_id,
                                    express_id: express_id,
                                    express_name: express_name,
                                    express_sn: express_sn,
                                    express_logo: express_logo
                                },
                                reload: true
                            });
                        }
                    })
                }
            },
            created: function() {
                var that = this;
                this.order_id = api.pageParam.order_id;

                this.getExpressList(function(res) {
                    that.sendList = res.data;
                    console.log(JSON.stringify(that.sendList))
                });

                api.addEventListener({
                    name: 'swiperight'
                }, function(ret, err) {
                    //这里写上你需要关闭的window或是frame
                    api.closeFrame({
                        animation: {
                            type: 'push',
                            subType: "from_left",
                            duration: 300
                        },
                    });

                });
            }
        };

        var even = function() {
            $(".header-btn").on('click', function() {
                api.closeFrame();
            })
        };
        var newVue = new Vue(vm);
        even();

    })
}
